package cn.kgc.ebookmanagement.service;

import cn.kgc.ebookmanagement.mapper.EbookentryMapper;
import cn.kgc.ebookmanagement.pojo.Ebookentry;
import cn.kgc.ebookmanagement.pojo.EbookentryExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.LongStream;

@Service
public class EbookentryServiceImpl implements  EbookentryService{
    @Resource
    EbookentryMapper ebookentryMapper;
    @Override
    public PageInfo<Ebookentry> slelect(Integer pageNum, Integer pageSize, Integer categoryId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Ebookentry>  ebookentryList;
        if(categoryId!=0){
            EbookentryExample ebookentryExample=new EbookentryExample();
            EbookentryExample.Criteria criteria=ebookentryExample.createCriteria();
            criteria.andCategoryidEqualTo(categoryId);
          ebookentryList=ebookentryMapper.selectByExample(ebookentryExample);
        }else {
          ebookentryList=ebookentryMapper.selectByExample(null);
        }

        PageInfo<Ebookentry> pageInfo=new PageInfo<>(ebookentryList);
        return pageInfo;
    }

    @Override
    public Integer add(Ebookentry entry) {
        int i=ebookentryMapper.insert(entry);
        return i;
    }

    @Override
    public Ebookentry seleteByid(Integer id) {
        Ebookentry ebookentry=ebookentryMapper.selectByPrimaryKey(id);
        return ebookentry;
    }

    @Override
    public Integer update(Ebookentry entry) {
        int i=ebookentryMapper.updateByPrimaryKeySelective(entry);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=ebookentryMapper.deleteByPrimaryKey(id);
        return i;
    }
}
